package com.rqbl.service.impl;


import com.rqbl.entity.Bar;
import com.rqbl.entity.User;
import com.rqbl.mapper.SubscribeMapper;
import com.rqbl.myutils.PageBean;
import com.rqbl.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bruce
 * @since 2024-07-19
 */
@Service
public class SubscribeServiceImpl implements SubscribeService {

    @Autowired
    private SubscribeMapper subscribeMapper;

    @Override
    public List<User> getSubscribeByBid(PageBean pageBean, Integer bid) {
        pageBean.setTotalSize(subscribeMapper.selectAllPostCountByBid(bid));
        int totalPage = pageBean.getTotalSize() / pageBean.getPageSize();
        if(pageBean.getTotalSize() % pageBean.getPageSize() != 0) {
            totalPage++;
        }
        pageBean.setTotalPage(totalPage);
        return subscribeMapper.getSubscribeByBid(bid,(pageBean.getPage()-1)*pageBean.getPageSize(),pageBean.getPageSize());
    }

    @Override
    public void insertSubscribeInfo(Integer uid, Integer bid) {
        subscribeMapper.insertSubscribeInfo(uid,bid);
    }

    @Override
    public void deleteSubInfo(Integer uid, Integer bid) {
        subscribeMapper.deleteSubInfo(uid,bid);
    }

    @Override
    public Integer getSubscribeByUB(Integer uid, Integer bid) {
        return subscribeMapper.getSubscribeByUB(uid,bid)==null ? 0 : 1;
    }

    @Override
    public List<Bar> getSubscribeByUid(PageBean pageBean, Integer uid) {
        pageBean.setTotalSize(subscribeMapper.selectAllPostCountByUid(uid));
        int totalPage = pageBean.getTotalSize() / pageBean.getPageSize();
        if(pageBean.getTotalSize() % pageBean.getPageSize() != 0) {
            totalPage++;
        }
        pageBean.setTotalPage(totalPage);
        return subscribeMapper.getSubscribeByUid((pageBean.getPage()-1)*pageBean.getPageSize(),uid,pageBean.getPageSize());
    }


}
